#!/bin/bash

# 脚本作者和博客地址
AUTHOR="zeruns"
BLOG_URL="https://blog.zeruns.tech"

echo "UnixBench Installer Script"
echo "Author: $AUTHOR"
echo "Blog: $BLOG_URL"
echo ""

# 检测包管理器
PACKAGE_MANAGER=""

if command -v apt-get >/dev/null 2>&1; then
    PACKAGE_MANAGER="apt-get"
elif command -v yum >/dev/null 2>&1; then
    PACKAGE_MANAGER="yum"
elif command -v dnf >/dev/null 2>&1; then
    PACKAGE_MANAGER="dnf"
else
    echo "No package manager found. Please install 'make', 'gcc', and 'git' manually."
    exit 1
fi

# 安装依赖
sudo $PACKAGE_MANAGER install -y make gcc git

# 下载源码
git clone https://gitee.com/zeruns/byte-unixbench.git

# 进入目录
cd byte-unixbench/UnixBench || { echo "Failed to enter UnixBench directory."; exit 1; }

# 编译
make

# 编译完成后，赋予执行权限
sudo chmod u+x ./Run
sudo chmod u+x -R ./*

# 开始测试
sudo ./Run
